package com.ytjj.qmyx.admin.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    /**
     * 指定时间增加n分钟
     * @param createTime 指定时间
     * @param minutes 需要增加的分钟值
     * @return
     */
    public static Date getFutureDate(Date createTime, Integer minutes) {
        Date result = new Date(createTime.getTime() + minutes * 60 * 1000);
        return result;
    }

    /**
     * 获取指定时间到当前时间的秒数
     * @param createTime
     * @return
     */
    public static long getDateGapBySecond(Date createTime) {
        long curTime = System.currentTimeMillis();
        long startTime = createTime.getTime();

        long gapSecond = (curTime - startTime) / 1000;
        return gapSecond;
    }

    /**
     * 通过时间秒毫秒数判断两个时间的间隔
     * @param beforeDate 20210711
     * @param afterDate 20210727
     * @return 16
     */
    public static int differentDaysByMillisecond(Date beforeDate, Date afterDate)
    {
        int days = (int) ((afterDate.getTime() - beforeDate.getTime()) / (1000*3600*24));
        return days;
    }

}
